package br.com.gerenciamento.pg.repository.jpa.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import br.com.gerenciamento.pg.repository.entity.Usuario;
import br.com.gerenciamento.pg.repository.jpa.UsuarioCustomDao;

@Repository
public class UsuarioCustomDaoImp implements UsuarioCustomDao {
	
	@PersistenceContext
	private EntityManager entityManager;
	
	private static final Logger LOGGER = LoggerFactory.getLogger(UsuarioCustomDaoImp.class);
	

	public List<Usuario> findAll() {
		final StringBuilder sql = new StringBuilder();
		sql.append("select * from usuario "); 
		
		Usuario u = null;
		
		try {
			final List<Object[]> list = entityManager.createNativeQuery(sql.toString()).getResultList();
			for (final Object[] o: list) {
				u = new Usuario();
				
				u.setId( ((BigDecimal)o[0]).longValue() );
				
			}
		} catch(Exception e) {
			LOGGER.error("Erro ao buscar dados para jde.", e);
		}
		
		return new ArrayList<Usuario>();
	}

}
